#更新计划单信息
import sys
sys.path.append("..")
import json
from flask import request
from db_client import *
import datetime
from create_id import get_id

def update_paln():
    #更新计划单信息
    token = request.headers.get('token')
    flag, right = token_client.check_token(token)
    if not flag:
        t = {
            'state': 'false',
            'msg': '更新失败'
        }
        return json.dumps(t, ensure_ascii=False)
    else:
        data = json.loads(request.get_data().decode('utf-8'))
        _id = data['id']
        it_id = data['item_id']
        count = data['count']
        unit_price = data['unit_price']
        s_id = data['supplier_id']
        state = data['state']
        total_price = int(count)*int(unit_price)
        __id = get_id('DD')

        flag2 = mysql_client.update_paln1(_id, it_id, count, unit_price, s_id, state, total_price, __id)
        if flag2:
            t = {
                'state': 'true',
                'msg': 'success'
            }
            return json.dumps(t, ensure_ascii=False)
        else:
            t = {
                'state': 'flase',
                'msg': '更新失败'
            }
            return json.dumps(t, ensure_ascii=False)
